<?php
// +----------------------------------------------------------------------
// | title: 标题注释
// +----------------------------------------------------------------------
// | Author: TZ.Leong
// +----------------------------------------------------------------------
// | Date: 2020/8/18 17:04
// +----------------------------------------------------------------------

namespace app\single\command;


use think\Command;
use think\Db;

class StatGopass extends Command
{
    protected function execute($input, $output)
    {
        if(date("H:i") == "00:00"){
            $day = date("Ymd", strtotime("-1 days"));
            $list = Db::table(config("database.game").".role_gopass")
                ->alias("rg")
                ->leftJoin([config("database.game").".role_pay_total" => "rp"], "rp.role_id = rg.role_id")
                ->where("level", ">", 0)
                ->group("level")
                ->column("{$day} AS `day`, COUNT(rg.role_id) AS num, COUNT(rp.role_id) AS pay_num", "level");
            if(false !== Db::table("c_stat_gopass")->where("day", $day)->delete()){
                Db::table("c_stat_gopass")->insertAll($list);
            }
        }
    }
}